﻿
var authorityArr = [];
function init() {

    if ($.getPara('op') == 'edit') {
        $('#opbtn').show();
    }

    getAuthority();
    function getAuthority() {
        $.ajaxHandler({
            url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
            urlType: "QueryDictItemList2",
            model: function () { return 998; },
            success: function (data) {
                if (data) {
                    authorityArr = data;

                    $('#SEE_SECR').append(createOption(data).join(''));

                    DOWN_PDF_SECRchange();
                    DOWN_SOURCE_SECRchange();
                    //setTimeout("initVal()", 200);
                    initVal();
                }
            }
        });
    }

    $('#SEE_SECR').change(function () { DOWN_PDF_SECRchange(); });
    $('#DOWN_PDF_SECR').change(function () { DOWN_SOURCE_SECRchange(); });


}
function initVal() {
    $.ajaxHandler({
        url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
        urlType: "GetCurrentFileOpre",
        model: function () { return $.getPara('roleid'); },
        success: function (data) {
            if (data) {

                $('#SEE_SECR').val(data.SEE_SECR);
                DOWN_PDF_SECRchange();
                $('#DOWN_PDF_SECR').val(data.DOWN_PDF_SECR);
                DOWN_SOURCE_SECRchange();
                $('#DOWN_SOURCE_SECR').val(data.DOWN_SOURCE_SECR);

            }
        }
    });
}
function DOWN_PDF_SECRchange() {
    var currentval = $('#SEE_SECR').val();

    var DOWN_PDF_SECRArr = [];
    $.each(authorityArr, function (i, item) {
        if (parseInt(item.ITEMVALUE) <= parseInt(currentval)) {
            DOWN_PDF_SECRArr.push(item);
        }
    });
    $('#DOWN_PDF_SECR').empty().append(createOption(DOWN_PDF_SECRArr).join(''));
}

function DOWN_SOURCE_SECRchange() {
    var currentval = $('#DOWN_PDF_SECR').val();

    var DOWN_PDF_SECRArr = [];
    $.each(authorityArr, function (i, item) {
        if (parseInt(item.ITEMVALUE) <= parseInt(currentval)) {
            DOWN_PDF_SECRArr.push(item);
        }
    });
    $('#DOWN_SOURCE_SECR').empty().append(createOption(DOWN_PDF_SECRArr).join(''));
}
function createOption(authorityArr) {
    var html = [];
    for (var i = 0; i < authorityArr.length; i++) {
        if (lang.SysLanguage == "en") {
            html.push('<option value="' + authorityArr[i].ITEMVALUE + '">' + authorityArr[i].ITEMDESC + '</option>');
        }
        else {
            html.push('<option value="' + authorityArr[i].ITEMVALUE + '">' + authorityArr[i].ITEMNAME + '</option>');
        }

    }
    return html;
}

function exit() {
    parent.$.closePage();
}

//#region 保存
function save() {
    $.ajaxHandler({
        url: App_Config.TadongUrl + "/AjaxMappingHandler.aspx",
        urlType: "EditRoleOpraRights",
        model: function () {
            var obj = {};
            obj.ROLES_ID = $.getPara('roleid');
            obj.SEE_SECR = $('#SEE_SECR').val();
            obj.DOWN_PDF_SECR = $('#DOWN_PDF_SECR').val();
            obj.DOWN_SOURCE_SECR = $('#DOWN_SOURCE_SECR').val();
            return $.toJSON(obj);
        },
        success: function (data) {
            if (data) {
                //$.alert("Success", "", function () { parent.$.closePage(); });
                alert(lang.pemission_assignment_complete);
                parent.$.closePage();
            }
        }
    });
}
//#endregion